<?php
namespace app\api\controller\v2\model\userInfo;

use think\Model;
use think\Db;


class UserInfo extends model
{
    //显示个人信息
    public function getShowUserInfo($user_id)
    {
        $result = Db::query("select * from user_info where user_id = '$user_id'");

        return $result;
    }

    //显示编辑用户资料
    public function getEditUserInfo($user_id)
    {
        $result = Db::query("select user_name,user_gender,user_age,user_desc,user_type,user_icon,background_img
                              from user_info
                              where user_id = '$user_id'");
        return $result;
    }

    //判断用户类型
    public function getJudgementUserType($user_id){
        $result = Db::query("select user_type from user_info where user_id = '$user_id'");
        return $result;
    }

    //显示被关注的人(粉丝)
    public function getShowFans($user_id,$other_user_id,$pageno){
        $pagesize = 10;
        $startno = $pageno*$pagesize;
        $arr = [];
        $fans_user_id = Db::table('ym_user_follow')->field('user_id')->where('follow_id',$other_user_id)->limit($startno,$pagesize)->select();
        // $follow_or_not = Db::table('ym_user_follow')->field('follow_or_not')->where('follow_id',$user_id)->select();
        $length = count($fans_user_id);
        for ($i=0; $i < $length; $i++) {
            $fans_id = $fans_user_id[$i]['user_id'];

            $follow_or_not = Db::table('ym_user_follow')->where('user_id',$user_id)->where('follow_id',$fans_id)->select();
            // var_dump($follow_or_not);
            $fans_user = Db::table('user_info')
                ->alias('a')
                ->join('ym_user_follow b','a.user_id = b.user_id')
                ->field(['a.user_id','a.user_name','a.user_icon','a.user_desc'])
                ->where('a.user_id',$fans_id)->where('b.follow_id',$other_user_id)
                ->select();

            if (!empty($follow_or_not)) {
                $fans_user[0]['follow_status'] = 1;
            }else{
                $fans_user[0]['follow_status'] = 0;
            }
            $arr[] = $fans_user[0];
        }
        return $arr;
    }

    //用户关注的人
    public function getShowFollows($user_id,$other_user_id,$pageno){
        $pagesize = 10;
        $startno = $pageno*$pagesize;
        $arr = [];
        $follow_user_id = Db::table('ym_user_follow')->field('follow_id')->where('user_id',$other_user_id)->limit($startno,$pagesize)->select();

        $length = count($follow_user_id);
        // echo $length;
        for ($i=0; $i < $length; $i++) {
            $follow_id = $follow_user_id[$i]['follow_id'];
            $follow_or_not = Db::table('ym_user_follow')->where('user_id',$user_id)->where('follow_id',$follow_id)->select();
            $follow_user = Db::table('user_info')->field(['user_id','user_name','user_icon','user_desc'])->where('user_id',$follow_id)->select();
            if (!empty($follow_or_not)) {
                $follow_user[0]['follow_status'] = 1;
            }else{
                $follow_user[0]['follow_status'] = 0;
            }
            $arr[] = $follow_user[0];
        }
        return $arr;
    }




















}